module nade.camera;

import derelict.opengl.gl;

import nade.think;
import nade.vector;
import nade.angle;


class Camera {
	this(const Vector2 position, const Vector2 size, const Degrees rotation)
	{
		_position = position;
		_hsize = size*0.5;
		_aspect = size.x/size.y;
		_rotation = rotation;
	}

	void render(void delegate() dg)
	{
		glPushMatrix();
		glScalef(1.0/hsize.x, 0.75/hsize.y, 1);
		glRotatef(-_rotation.degrees, 0, 0, 1);
		glTranslatef(-_position.x, -_position.y, 0);

		dg();

		glPopMatrix();
	}

	Vector2 position() { return _position; }
	Vector2 position(Vector2 rhs) { return _position = rhs; }

	Vector2 hsize() { return _hsize; }
	Vector2 hsize(Vector2 rhs) { _aspect = rhs.x/rhs.y; return _hsize = rhs; }
	Vector2 hsize(real rhs) { return _hsize = Vector2(rhs, rhs/_aspect); }

	Vector2 size() { return _hsize*2; }
	Vector2 size(Vector2 rhs) { _aspect = rhs.x/rhs.y; return _hsize = rhs*0.5; }
	Vector2 size(real rhs) { return _hsize = Vector2(rhs*0.5, rhs*0.5/_aspect); }

	real aspect() { return _aspect; }
	real aspect(real rhs) { return _aspect = rhs; }

	Degrees rotation() { return _rotation; }
	Degrees rotation(Degrees rhs) { return _rotation = rhs; }

	private {
		Vector2		_position;
		Vector2		_hsize;
		real		_aspect;
		Degrees		_rotation;
	}
}
